using System.Collections.Generic;

namespace Test.ConsoleProgram.Algorithm.Solution
{
    [TestDescription("算法: 1207. 独一无二的出现次数")]
    public class No1207_UniqueOccurrences : AbsBaseTestItem
    {
        /*
        给你一个整数数组 arr，请你帮忙统计数组中每个数的出现次数。
        如果每个数的出现次数都是独一无二的，就返回 true；否则返回 false。
        提示：
            1 <= arr.length <= 1000
            -1000 <= arr[i] <= 1000
        */

        public override void OnTest()
        {
            Assert.TestExe(UniqueOccurrences, new int[] { 1, 2, 2, 1, 1, 3 }, true);
            Assert.TestExe(UniqueOccurrences, new int[] { 1, 2 }, false);
            Assert.TestExe(UniqueOccurrences, new int[] { -3, 0, 1, -3, 1, 1, 1, -3, 10, 0 }, true);
        }

        public bool UniqueOccurrences(int[] arr)
        {
            var dic_count = new Dictionary<int, int>();
            for (int i = 0; i < arr.Length; i++)
            {
                dic_count[arr[i]] = dic_count.GetValueOrDefault(arr[i], 0) + 1;
            }
            var dic_ans = new Dictionary<int, int>();
            foreach (var key in dic_count.Keys)
            {
                dic_ans[dic_count[key]] = key;
            }
            return dic_count.Count == dic_ans.Count;
        }
    }
}
